﻿using System;
using System.Collections;
using System.Web.Script.Serialization;

namespace WSTest
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnDataTable_Click(object sender, EventArgs e)
        {
            var client = new ExpenseQueue.ExpenseQueueSoapClient();
            var table = client.GetExpenseQueueDataTable();
            gvExpense.DataSource = table;
            gvExpense.DataBind();
        }

        protected void btnJSON_Click(object sender, EventArgs e)
        {
            var client = new ExpenseQueue.ExpenseQueueSoapClient();
            var s = client.GetJSONStringOfExpenseQueue();
            var jsSerializer = new JavaScriptSerializer();
            var list = jsSerializer.Deserialize<IList>(s);
            if (null == list || list.Count == 0)
                return;

            Response.Write("<OL>");
            foreach (var item in list)
            {
                var dict = item as IDictionary;
                if (null != dict)
                {
                    Response.Write("<LI>");

                    foreach (var key in dict.Keys)
                    {
                        var value = dict[key];
                        var sValue = null == value ? "(N/A)" : value.ToString();

                        Response.Write(key.ToString() + ": " + sValue + "<br/>");
                    }

                    Response.Write("</LI>");
                }
            }
            Response.Write("</OL>");
        }
    }
}
